<template>
  <div class="review-list">
    <el-empty v-show="!tableData.length" description="暂无数据"></el-empty>
    <List v-if="tableData.length" :tableData="tableData" :deleteShow="true" />
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
import { sysEvaluateQuery, sysEvaluateDelete } from '@/api/home/sysEvaluate.js'
import Bus from '@/utils/bus.js'
export default {
  components: {
    List: () => import('@/components/review/List.vue'),
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 6,
        resId: '',
        // resId: this.$store.getters.knowledgeId,
        type: 1,
        resType: 2,
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    this.getList()
    Bus.$on('refreshReviewList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
    Bus.$on('sendKnowledgeId', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshReviewList')
    Bus.$off('sendKnowledgeId')
  },
  methods: {
    getList() {
      if (!this.listQuery.resId) return
      sysEvaluateQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.tableData.forEach((v) => {
          v.score = parseInt(v.score)
        })
        this.pageObj = res.data
      })
    },
    handleLook(row) {
      Bus.$emit('showDialogReviewInfo', row)
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      sysEvaluateDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>
<style scoped>
.review-list {
  max-height: 700px;
  overflow-y: scroll;
}
/* .review-list::-webkit-scrollbar {
  display: none;
} */
</style>